package Translate;

import Temp.*;

abstract class Cx extends Exp {

    @Override
    Tree.Exp unEx() {
        Label l = new Label();
        Label l2 = new Label();
        Temp t = new Temp();

        return new Tree.ESEQ(new Tree.SEQ(new Tree.MOVE(new Tree.TEMP(t),
                new Tree.CONST(1)), new Tree.SEQ(unCx(l, l2), new Tree.SEQ(
                                new Tree.LABEL(l2), new Tree.SEQ(new Tree.MOVE(new Tree.TEMP(t),
                                                new Tree.CONST(0)), new Tree.LABEL(l))))),
                new Tree.TEMP(t));
    }

    abstract Tree.Stm unCx(Label l, Label l2);

    @Override
    Tree.Stm unNx() {
        Temp t = new Temp();
        Label l = new Label();
        Label l2 = new Label();

        return new Tree.SEQ(new Tree.MOVE(new Tree.TEMP(t), new Tree.CONST(1)),
                new Tree.SEQ(unCx(l, l2), new Tree.SEQ(new Tree.LABEL(l2),
                                new Tree.SEQ(new Tree.MOVE(new Tree.TEMP(t),
                                                new Tree.CONST(0)), new Tree.LABEL(l)))));
    }
}
